package com.aat.dizena.web;

import com.aat.dizena.bean.User;
import com.aat.dizena.service.UserService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Iterator;

@RestController
@RequestMapping("user")
public class UserController
{
    @Resource
    private UserService service;

    @GetMapping("list")
    public Iterator<User> list()
    {
        User m = service.findById(1L);
        if (m == null)
        {
            service.init();
        }
        return service.findAll();
    }

    @GetMapping("get/{id}")
    public User get(@PathVariable("id") Long id)
    {
        return service.findById(id);
    }

    @GetMapping("nickname")
    public Page<User> nickname(@RequestParam String str)
    {
        String field = "nickname";
        return service.search(field, str);
    }

    @GetMapping("tags")
    public Page<User> tags(@RequestParam String str)
    {
        String field = "tags";
        return service.search(field, str);
    }


}
